<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('成本结算')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<style>
    select {
        padding-top: 3px !important;
    }

    .select-list {
        margin-top: 5px !important;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="settlement-form">
                <input type="hidden" id="fillFlag" th:value="${fillFlag}">
                <div class="col-sm-12">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>项目名称：</p>
                                <input type="text" name="proName" class="form-control">
                            </li>
                            <li>
                                <p>工程公司：</p>
                                <select name="compName" th:with="compName=${@dict.getType('company')}"
                                        class="form-control">
                                    <option value="">请选择</option>
                                    <option th:each="compName : ${compName}" th:text="${compName.dictLabel}"
                                            th:value="${compName.dictLabel}" th:title="${compName.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()">
                <i class="fa fa-plus"></i> 新增
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: echarts-js"/>
<script th:inline="javascript">
    var prefix = ctx + "costSettlement";

    $(function () {
        var options = {
            uniqueId: "id",
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            modalName: "成本结算",
            columns: [{
                checkbox: true
            },
                {
                    field: 'billNo',
                    title: '编号'
                },
                {
                    field: 'proName',
                    title: '项目名称'
                },
                {
                    field: 'compName',
                    title: '工程公司'
                },
                {
                    field: 'businessManager',
                    title: '商务经理'
                },
                {
                    field: 'auditContent',
                    title: '审核内容'
                },
                {
                    field: 'teamInfo',
                    title: '分包班组信息'
                },
                {
                    field: 'applyMoney',
                    title: '申请金额'
                },
                {
                    field: 'settlementMoney',
                    title: '结算审定金额'
                },
                {
                    field: 'reduceMoney',
                    title: '核减值'
                },
                {
                    field: 'reduceRate',
                    title: '核减率'
                },
                {
                    field: 'reduceReason',
                    title: '核减原因'
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        if (row.isFiled == 1) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="approval(\'' + row.id + '\')"><i class="fa fa-edit"></i>审定</a> ');
                            actions.push('<a class="btn btn-info  btn-xs" href="javascript:void(0)" onclick="submitFinal(\'' + row.id + '\',\'' + row.settlementMoney + '\')"><i class="fa fa-plus"></i>提交</a> ');
                        } else if (row.isFiled == 2) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="approval(\'' + row.id + '\')"><i class="fa fa-edit"></i>审定</a> ');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="isFiled(\'' + row.id + '\',\'' + row.finalMoney + '\')"><i class="fa fa-edit"></i>归档</a> ');
                        } else {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-info  btn-xs" href="javascript:void(0)" onclick="submitUser(\'' + row.id + '\')"><i class="fa fa-plus"></i>提交</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        if ($("#fillFlag").val() == 0) {
            $("#toolbar").hide();
        } else {
            $("#toolbar").show();
        }
    });

    function submitUser(id) {
        $.modal.open('提交', prefix + '/submitUser?id=' + id, '', 420);
    }

    function submitFinal(id, settlementMoney) {
        if (settlementMoney != "null") {
            $.operate.get(prefix + '/submitFinal?id=' + id);
        } else {
            $.modal.alertWarning("请把信息填写完整！")
        }
    }

    function approval(id) {
        $.modal.open('审定', prefix + '/approval?id=' + id);
    }

    function isFiled(id, finalMoney) {
        if (finalMoney != "null") {
            $.operate.get(prefix + '/isFiled?id=' + id);
        } else {
            $.modal.alertWarning("请把信息填写完整！")
        }
    }

</script>
</body>
</html>